<template>
  <header class="todo-header">
    <h1 class="todo-title">{{ title }}</h1>
    <div class="input-container">
      <input 
        v-model="taskText" 
        @keyup.enter="addTask" 
        placeholder="请输入新的任务..." 
        class="task-input"
      />
      <button @click="addTask" class="add-button">
        <span class="button-text">添加</span>
        <span class="button-icon">+</span>
      </button>
    </div>
  </header>
</template>

<script setup>
import { ref } from 'vue';

// 定义props
const props = defineProps({
  title: {
    type: String,
    default: '待办事项列表'
  }
});

// 定义事件
const emit = defineEmits(['add-task']);

// 本地状态
const taskText = ref('');

// 添加任务方法
const addTask = () => {
  if (taskText.value.trim()) {
    emit('add-task', taskText.value);
    taskText.value = '';
  }
};
</script>

<style scoped>
.todo-header {
  margin-bottom: 30px;
}

.todo-title {
  text-align: center;
  color: #2c3e50;
  font-size: 28px;
  margin-bottom: 20px;
  position: relative;
  font-weight: 600;
}

.todo-title::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background-color: #41b883; /* Vue绿色 */
  border-radius: 3px;
}

.input-container {
  display: flex;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  overflow: hidden;
}

.task-input {
  flex: 1;
  padding: 14px 16px;
  border: none;
  outline: none;
  font-size: 16px;
  background-color: #fff;
}

.task-input::placeholder {
  color: #aaa;
}

.add-button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  background-color: #41b883; /* Vue绿色 */
  color: white;
  border: none;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s ease;
  min-width: 100px;
}

.add-button:hover {
  background-color: #35495e; /* Vue深色 */
}

.button-text {
  margin-right: 5px;
}

.button-icon {
  font-size: 18px;
  font-weight: bold;
}
</style> 